home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_casm / snpd9611.zip / ANSIFLEN.C < prev    next >
C/C++ Source or Header  |  1996-11-24  |  1KB  |  55 lines

  1. .I 0 2
  2. /* +++Date last modified: 09-Nov-1996 */
  3.  
  4. .I 9 37
  5. #if defined(__cplusplus) && __cplusplus /* C++ version follows */
  6.  
  7.  #include <fstream.h>
  8.  
  9.  long flength(char *fname)
  10.  {
  11.        long length = -1L;
  12.        ifstream ifs;
  13.  
  14.        ifs.open(fname, ios::binary);
  15.        if (ifs)
  16.        {
  17.              ifs.seekg(0L, ios::end) ;
  18.              length = ifs.tellg() ;
  19.        }
  20.        return length;
  21.  }
  22.  
  23. #else /* Straight C version follows */
  24.  
  25.  long flength(char *fname)
  26.  {
  27.        long length = -1L;
  28.        FILE *fptr;
  29.  
  30.        fptr = fopen(fname, "rb");
  31.        if(fptr != NULL)
  32.        {
  33.              fseek(fptr, 0L, SEEK_END);
  34.              length = ftell(fptr);
  35.              fclose(fptr);
  36.        }
  37.  
  38.        return length;
  39.  }
  40.  
  41. #endif /* C++ */
  42. .D 10 15
  43. .I 36 10
  44.       char *ptr;
  45.       long len;
  46.  
  47.       while (--argc)
  48.       {
  49.             len = flength(ptr = *(++argv));
  50.             if (-1L == len)
  51.                   printf("\nUnable to get length of %s\n", ptr);
  52.             else  printf("\nLength of %s = %ld\n", ptr, len);
  53.       }
  54. .D 37 1
  55.